package com.dawnling.androidutils.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.dawnling.androidutils.R;
import com.dawnling.androidutils.utils.ScreenShot;
import com.dawnling.androidutils.view.ShotView;

public class ShotActivity extends AppCompatActivity {

    //截图按钮
    private Button shotButton = null;
    //截图的view
    private ShotView shotView = null;
    private TextView textView = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shot);
        textView= ( TextView ) findViewById( R.id.textview );
        shotButton = (Button) findViewById( R.id.shotBtn );
        shotButton.setOnClickListener( new View.OnClickListener(){
            @Override
            public void onClick( View v ){
                if ( shotView == null ){
                    shotView = (ShotView) findViewById( R.id.shotView );
                }
                else{
                    shotView.setIsRunning(true);
                }

                Bitmap bgBitmap = shotView.getBitmap( );
                if ( bgBitmap != null ){
                    bgBitmap.recycle( );
                }
                bgBitmap = ScreenShot.takeScreenShot( ShotActivity.this );
                shotView.setBitmap( bgBitmap );
                shotView.setVisibility( View.VISIBLE );
            }
        } );
    }
}